﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InTheHand.Net;
using System.IO;
using InTheHand.Net.Sockets;
using InTheHand.Net.Bluetooth;
using System.Net.Sockets;
using InTheHand.Net.Mime;
using System.Net;

namespace BlueRadar.API
{
    public class BlueSender
    {
        private Device TargetDevice;
        private string FilePath;

        public BlueSender(Device device, string File)
        {
            this.TargetDevice = device;
            this.FilePath = File;
        }

        public void SendFile()
        {
            string FileName = Path.GetFileName(FilePath);
            BluetoothAddress address = TargetDevice.DeviceAddress;
            Uri uri = new Uri("obex-push://" + address.ToString() + "/" + FileName);

            ObexWebRequest request = new ObexWebRequest(uri);
            request.ReadFile(FilePath);            
            string RequestState = string.Empty;
            //request.ContentType = MediaTypeNames.Image.Jpg;
            try
            {
                ObexWebResponse response = (ObexWebResponse)request.GetResponse();
                RequestState = response.StatusCode.ToString();
                response.Close();
            }
            catch (WebException we)
            {
                RequestState = we.Message;
            }
            finally
            {
                TargetDevice.LastSendStatus = RequestState;
            }
        }
    }
}
